<?php
declare(strict_types=1);

namespace App\Controller\WebApi\v1;

use App\Controller\AbstractController;
use Hyperf\HttpServer\Contract\RequestInterface;
use Hyperf\HttpServer\Annotation\RequestMapping;
use Hyperf\HttpServer\Annotation\Controller;
use App\Middleware\WebApiMiddleware;
use Hyperf\HttpServer\Annotation\Middleware;
use Service\MemberService\MemberCollectionService;
use Hyperf\Di\Annotation\Inject;

/**
 * 用户收藏
 * @author huj
 * @Controller(prefix="/webapi/v1/membercollection")
 * @Middleware(WebApiMiddleware::class)
 */
class MemberCollectionController extends AbstractController
{
     /**
     * 通过 `@Inject` 注解注入由 `@var` 注解声明的属性类型对象
     * @Inject()
     * @var MemberCollectionService
     */
    protected $memberCollectionService;

    /**
     * 收藏列表
     * @RequestMapping(path="index", methods="get,post")
     */
    public function index(RequestInterface $request)
    {
        $param        = $request->inputs(['page', 'limit']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberCollectionService->collectionList($param);
    }

    /**
     * 添加收藏
     * @RequestMapping(path="add", methods="get,post")
     */
    public function add(RequestInterface $request)
    {
        $param        = $request->inputs(['type', 'id']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberCollectionService->add($param);
    }

    /**
     * 取消收藏
     * @RequestMapping(path="cancel", methods="get,post")
     */
    public function cancel(RequestInterface $request)
    {
        $param        = $request->inputs(['belong_id', 'type']);
        $param['mid'] = $request->getAttribute('mid');
        return $this->memberCollectionService->cancel($param);
    }
}